package org.jeecg.modules.parameter.biz.controlltr;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.parameter.api.dto.platform.SimPlatformDto;
import org.jeecg.modules.parameter.api.entity.SimPlatform;
import org.jeecg.modules.parameter.api.vo.platform.SimPlatformVo;
import org.jeecg.modules.parameter.biz.service.SimStationPlatformService;
import org.jeecg.modules.parameter.common.api.dto.PatchPO;
import org.jeecg.modules.parameter.common.utils.oConvertUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lsy
 * @date 2024/09/17
 */
@Api(tags = "参数管理-车站-站台管理")
@RestController
@RequestMapping(value = {"/stationPlatformInfo"}, produces = {"application/json; charset=utf-8"})
@Slf4j
public class SimStationPlatformController extends JeecgController<SimPlatform, SimStationPlatformService> {
    @Resource
    private SimStationPlatformService platformService;

    @ApiOperation(value = "按车站ID查询站台信息", notes = "按车站ID查询站台信息")
    @PostMapping(value = "/getPlatformBySataId")
    public Result<List<SimPlatformVo>> getPlatformBySataId(@RequestParam(name = "stationId", required = true) String id) {
        List<SimPlatformVo> simPlatformVo = oConvertUtils.entityListToModelList(platformService.getPlatformBySataId(id), SimPlatformVo.class);
        return Result.ok(simPlatformVo);
    }

    @ApiOperation(value = "按ID删除车站站台", notes = "按ID删除车站站台")
    @DeleteMapping(value = "/delPlatform")
    public Result<String> delPlatform(@RequestParam(name = "id", required = true) String id) {
        platformService.removeById(id);
        return Result.ok("删除成功");
    }

    @ApiOperation(value = "按ID查询车站站台", notes = "按ID查询车站站台")
    @PostMapping(value = "/queryPlatformById")
    public Result<SimPlatformVo> queryPlatformById(@RequestParam(name = "id", required = true) String id) {
        return Result.ok(oConvertUtils.entityToModel(platformService.getById(id), SimPlatformVo.class));
    }

    @ApiOperation(value = "添加车站站台信息", notes = "添加车站站台信息")
    @PostMapping(value = "/addPlatform")
    public Result<String> addPlatform(@RequestBody SimPlatformDto simPlatformDto) {
        SimPlatform simPlatform = oConvertUtils.entityToModel(simPlatformDto, SimPlatform.class);
        platformService.save(simPlatform);
        return Result.ok("保存成功");
    }


    @ApiOperation(value = "修改车站站台信息", notes = "修改车站站台信息")
    @PutMapping(value = "/updatePlatform")
    public Result<String> updatePlatform(@RequestBody PatchPO patchPO) {
        platformService.updatePatch(patchPO);
        return Result.OK("更新成功!");
    }

}
